<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>6_5_3-Teleport全局弹窗</title>
</head>

<body>


  <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
  <div id="Application">
    <div style="position: absolute; width: 50px; border: red solid 2px">
      <my-alert></my-alert>
    </div>
  </div>
  <script>
    const App = Vue.createApp({});
    App.component("my-alert", {
      template: `
          <div>
              <button @click="show = true">弹出弹窗</button>
              </div>
              <!--这里是重点-->
              <teleport to="body">  
              <div v-if="show" style="text-align:center;
              padding:20px;
              position:absolute;
              top:45%;
              left:30%;
              width:40%;
              border:black solid 2px;
              background-color:white">
              <h3>弹窗</h3>
              <button @click="show = false">隐藏弹窗</button>
              </div>
              </telport>
          `,
      data() {
        return {
          show: false,
        };
      },
    });
    App.mount("#Application");
  </script>
</body>

</html>